<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜单操作</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
    <script src="/static/admin/jquery/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <form action="" class="layui-form">
        <input type="hidden" {if !empty($data) }value="{$data.id}"{/if} name="id">
        <div class="layui-form-item clearfix">
        <div class="layui-form-item clearfix">
            <label class="layui-form-label">父级菜单</label>
            <div class="layui-input-inline">
                <select name="parent" lay-verify="required" lay-filter="rule-select">
                    <option value="0">无父级菜单</option>
                    {foreach name = "first_menu" item = "vo"}
                    <option value="{$vo.id}" {if condition="!empty($data) && $data['parent']==$vo['id']"}selected{/if}>{$vo.title}---{$vo.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input input-w" {if !empty($data) }value="{$data.title}"{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单URL</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" autocomplete="off" class="layui-input input-w" {if !empty($data) }value="{$data.name}"{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型-默认菜单</label>
            <div class="layui-input-block">
              <input type="checkbox" name="type" {if !empty($data) }{eq name="$data['type']" value="1" }checked=""{/eq}{/if} lay-skin="switch" lay-text="按钮|菜单">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开关-默认关</label>
            <div class="layui-input-block">
              <input type="checkbox" name="status" {if !empty($data) }{eq name="$data['status']" value="1" }checked=""{/eq}{/if} lay-skin="switch" lay-text="开|关">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script src="/static/admin/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">

    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                type : "POST",  //提交方式
                url : "{:url('/admin/auth/menu_edit')}",//路径
                data : $('form').serialize(),
                success: function(data){
                    layer.msg(data.msg)
                    if(data.code == 0){
                        setTimeout(function () {
                            // layer.close(index);
                            parent.location.reload();
                        }, 2000);

                    }
                }
            });
            return false;
        });
    });

</script>
</body>
</html>